<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta name="screen-orientation" content="portrait">
    <meta name="x5-orientation" content="portrait">
    <title>聚财通</title>
    <link rel="stylesheet" href="../../styles/h5/reset.min.css"/>
    <link rel="stylesheet" href="../../styles/h5/errortankuang.css"/>
    <!--以上为公共css样式-->
    <link rel="stylesheet" href="../../styles/h5/fund.css"/>

    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery-1.9.1.min.js"></script>
    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery.modal.js"></script>
    <!--以上为公共js文件-->
</head>
<body>
<div class="zz-top-16"></div>
<div class="zz-profitHeader-jj clear">
    <div class="zz-pHeader-jj zz-sevenProfit-jj zz-profitHeaderColor-jj" choiceProfit="annual7D">
        <span class="zz-border-jj zz-sevenBorder-jj zz-borderColor-jj"></span>
        七日年化
    </div>
    <div class="zz-pHeader-jj zz-wanfenProfit-jj" choiceProfit="oppositeDate">
        <span class="zz-border-jj zz-wanfenBorder-jj"></span>
        万份收益
    </div>
</div>
<div class="zz-fundProfit-jj">
    <p class="zz-oneMonth"><span id="zz-oneMonthProfit">近一月平均收益率</span><span class="zz-wenhao-jj"></span></p>
    <p class="zz-fundPercent-jj" id="zz-fundPercent-jj"></p>
</div>
<div class="zz-top-10"></div>
<div class="zz-fundProfitList-jj">
    <ul>
        <!--<li>
            <p class="zz-fundP-jj clear">
                <span class="zz-fundL-jj">2017-09-19</span>
                <span class="zz-fundR-jj">4.0666%</span>
            </p>
        </li>-->
    </ul>
</div>

</body>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/utils.js"></script>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/index.js"></script>
<script>
	
	var queryURLParameter = utils.queryURLParameter();
    var choiceP = queryURLParameter.choiceP;
    if(choiceP =="oppositeDate"){
        $(".zz-sevenProfit-jj").removeClass("zz-profitHeaderColor-jj")
        $(".zz-sevenBorder-jj").removeClass("zz-borderColor-jj")
        $(".zz-wanfenProfit-jj").addClass("zz-profitHeaderColor-jj")
        $(".zz-wanfenBorder-jj").addClass("zz-borderColor-jj");

        $("#zz-oneMonthProfit").html("近一个月平均万份收益" + "(元)");
    }
	
    var $pHeader = $(".zz-pHeader-jj");
    var $fundPercent = $("#zz-fundPercent-jj");
    var choiceProfit = "";
    var data = '';
    var aveSyl = "";
    var aveDwjz = "";
    var maxSyl = "";
    var maxDwjz = "";
    var minSyl = "";
    var minDwjz = "";
    var everyWidth = "";
    var title = "近一个月平均收益率";
    var content = "以基金合作渠道公布的官方收益数据统计最近一个月平均水平得出，实际收益以基金公司实际发放为准";
    //var flag = true;

    bindChart();
    function bindChart() {
        $.ajax({
            url: utils.ajaxUrl()+"h5/fundQuery/chartQuery",
            data: {
                dateSlot: 2
            },
            async: false,
            type: 'get',
            success: function (res) {
                //var res = JSON.parse(res);
                console.log(res);
                if (res && res.retCode == '0000') {
                    aveSyl = res.aveSyl;//平均七日
                    aveDwjz = res.aveDwjz;//平均万份
                    maxSyl = res.maxSyl;//最大七日
                    maxDwjz = res.maxDwjz;//最大万份
                    minSyl = res.minSyl;//最小七日
                    minDwjz = res.minDwjz;//最小万份
                    
                    choiceProfit = $(".zz-profitHeaderColor-jj").attr("choiceProfit");
                    if (choiceProfit == "annual7D") {
                        $fundPercent.html(aveSyl + "%");
                    } else if (choiceProfit == "oppositeDate") {
                        $fundPercent.html(aveDwjz);
                    }
                    if(res.fundRateList != null && res.fundRateList.length>0){
                        data = (res.fundRateList).reverse();
                        bindHTML();
                    }
                } else {
                    utils.error("sx.png", "啊哦，数据异常");
                }
            },
            error: function () {
                utils.error("wlyc.png", "啊哦，连接不到网络呢");
            }
        });
    }

    function bindHTML() {
        var str = "";
        choiceProfit = $(".zz-profitHeaderColor-jj").attr("choiceProfit");
        for (var j = 0; j < data.length; j++) {
            var curData = data[j];
            str += '<li>';
            if (choiceProfit == "annual7D") {
                if(curData.annual7D == maxSyl){
                    everyWidth = "100";
                }else if(curData.annual7D == minSyl){
                    everyWidth = "50";
                }else{
                    everyWidth = (0.5+0.5*((curData.annual7D-minSyl)/(maxSyl-minSyl)))*100;
                }
                str += '<p class="zz-fundP-jj clear" style="width: '+everyWidth+'%">';
                str += '<span class="zz-fundL-jj">' + curData.oppositeDate + '</span>';
                str += '<span class="zz-fundR-jj" >' + curData.annual7D + '%</span>';
            } else if (choiceProfit == "oppositeDate") {
                if(curData.oppositeDate == maxDwjz){
                    everyWidth = "100";

                }else if(curData.unitAccrua == minDwjz){
                    everyWidth = "50";
                }else{
                    everyWidth = (0.5+0.5*((curData.unitAccrua - minDwjz)/(maxDwjz - minDwjz)))*100;
                }
                str += '<p class="zz-fundP-jj clear" style="width: '+everyWidth+'%">';
                str += '<span class="zz-fundL-jj">' + curData.oppositeDate + '</span>';
                str += '<span class="zz-fundR-jj">' + curData.unitAccrua + '</span>';
            }
            str += '</p>';
            str += '</li>';
        }
        $(".zz-fundProfitList-jj ul").html(str);
    }

    $pHeader.click(function () {
        var $this = $(this);
        if ($this.hasClass("zz-profitHeaderColor-jj")) {
            return false;
        }
        $this.addClass("zz-profitHeaderColor-jj").siblings().removeClass("zz-profitHeaderColor-jj");
        $this.children(".zz-border-jj").addClass("zz-borderColor-jj");
        $this.siblings().children(".zz-border-jj").removeClass("zz-borderColor-jj");
        choiceProfit = $(".zz-profitHeaderColor-jj").attr("choiceProfit");
        if (choiceProfit == "annual7D") {
            title = "近一个月平均收益率";
            $("#zz-oneMonthProfit").html(title);
            $fundPercent.html(aveSyl + "%");
        } else if (choiceProfit == "oppositeDate") {
            title = "近一个月平均万份收益";
            $("#zz-oneMonthProfit").html(title + "(元)");
            $fundPercent.html(aveDwjz);
        }
        bindHTML();
    });

    $(".zz-wenhao-jj").click(function () {
        new $.modal({
            title: title,//弹框title
            content: content,//弹框内容
//            serviceCharge:"服务费￥100元，到账金额3433元",
            confirm: "确定",//确认按钮里面内容
            isshowclosebtn: false,//是否显示取消按钮
            showcontent: false,//false为弹出框组件二，true为弹出框组件一
            closecallback: function () {
            },//点击关闭时触发事件
            surecallback: function () {
                //点击确定时触发事件
            }
        }).show();
    });

    //初始化图表数据.


</script>
</html>